package Work;

import java.sql.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Scanner;

public class uifind {
	Statement state;// 执行对象
	// 执行查询书籍SQL语句(返回图书列表)
	public ArrayList<Record> uifindRecord(Jdbc db, int i, String s) {
		ArrayList<Record> array = new ArrayList<>();
		int count = 0;// 计数变量
		try {
			if (i == 1) {// 选择1 按书籍id查询
				String sqlstr1 = "select * from record where b_id = '"+ s +"\'";
				ResultSet resultSet = this.state.executeQuery(sqlstr1);
				while(resultSet.next()) {
					Record record = new Record();
					record.setB_ID(resultSet.getString("b_id"));
					record.setR_ID(resultSet.getString("r_id"));
					record.setBorrow_time(resultSet.getString("borrow_time"));
					record.setReturn_time(resultSet.getString("return_time"));
					record.setReborrow_time(resultSet.getString("reborrow_time"));
					record.setLib_confirm(resultSet.getString("lib_confirm"));
					count++;
					array.add(record);
				}  
			} else if (i == 2) {// 选择1 按读者id查询
				String sqlstr1 = "select * from record where r_id = '"+ s +"\'";
				ResultSet resultSet = this.state.executeQuery(sqlstr1);
				while(resultSet.next()) {
					Record record = new Record();
					record.setB_ID(resultSet.getString("b_id"));
					record.setR_ID(resultSet.getString("r_id"));
					record.setBorrow_time(resultSet.getString("borrow_time"));
					record.setReturn_time(resultSet.getString("return_time"));
					record.setReborrow_time(resultSet.getString("reborrow_time"));
					record.setLib_confirm(resultSet.getString("lib_confirm"));
					count++;
					array.add(record);
				}  
			}else if (i == 3) {// 选择1 按读者id查询
				String sqlstr1 = "select * from record where lib_confirm = '"+ s +"\'";
				ResultSet resultSet = this.state.executeQuery(sqlstr1);
				while(resultSet.next()) {
					Record record = new Record();
					record.setB_ID(resultSet.getString("b_id"));
					record.setR_ID(resultSet.getString("r_id"));
					record.setBorrow_time(resultSet.getString("borrow_time"));
					record.setReturn_time(resultSet.getString("return_time"));
					record.setReborrow_time(resultSet.getString("reborrow_time"));
					record.setLib_confirm(resultSet.getString("lib_confirm"));
					count++;
					array.add(record);
				}  
			} else if (i == 4) {// 选择2 按读者姓名查询
				String sqlstr2 = "select * from record where borrow_time = '"+ s +"\'";
				ResultSet resultSet = this.state.executeQuery(sqlstr2);
				while(resultSet.next()) {
					Record record = new Record();
					record.setB_ID(resultSet.getString("b_id"));
					record.setR_ID(resultSet.getString("r_id"));
					record.setBorrow_time(resultSet.getString("borrow_time"));
					record.setReturn_time(resultSet.getString("return_time"));
					record.setReborrow_time(resultSet.getString("reborrow_time"));
					record.setLib_confirm(resultSet.getString("lib_confirm"));
					count++;
					array.add(record);
				} 
			} else if (i == 5) {// 选择3 按读者电话查询
				String sqlstr3 = "select * from record where return_time = '"+ s +"\'";
				ResultSet resultSet = this.state.executeQuery(sqlstr3);
				while(resultSet.next()) {
					Record record = new Record();
					record.setB_ID(resultSet.getString("b_id"));
					record.setR_ID(resultSet.getString("r_id"));
					record.setBorrow_time(resultSet.getString("borrow_time"));
					record.setReturn_time(resultSet.getString("return_time"));
					record.setReborrow_time(resultSet.getString("reborrow_time"));
					record.setLib_confirm(resultSet.getString("lib_confirm"));					
					count++;
					array.add(record);
				} 
			} 
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (count == 0)
			return null;
		return array;
	}
}
